package com.kgc.config;

import com.wechat.pay.java.core.RSAAutoCertificateConfig;

/**
 * 单例模式
 *
 * @author sheep
 */
public class WxPayConfig {

    /**
     * 商户号
     */

    private final String merchantId = "1606612310";

    /**
     * 商户API私钥路径
     */

    private final String privateKeyPath = WxPayConfig.class.getClassLoader().getResource("apiclient_key.pem").getPath();

    /**
     * 商户证书序列号
     */

    private final String merchantSerialNumber = "328B40F3A627A7E88A714FF5CA8027BE767EF3F2";

    /**
     * 商户APIV3密钥
     */

    private final String apiV3key = "hnjyet993603562456bdqn4685030352";

    /**
     * 应用程序ID
     */
    private final String appid = "wxa738052168ff7dc8";
    /**
     * 微信支付回调地址，需修改成内网穿透的域名地址
     */
    private final String notifyUrl = "http://7f0f617d.r23.cpolar.top/wx/wxNotify";

    // RSA自动证书配置类
    private final RSAAutoCertificateConfig config;

    private static final WxPayConfig wxPayConfig = new WxPayConfig();

    private WxPayConfig() {
        // 根据基本参数构建RSAAutoCertificateConfig对象
        config = new RSAAutoCertificateConfig.Builder()
                .merchantId(merchantId)
                .privateKeyFromPath(privateKeyPath)
                .merchantSerialNumber(merchantSerialNumber)
                .apiV3Key(apiV3key)
                .build();
    }

    public static WxPayConfig instance() {
        return wxPayConfig;
    }

    // 反回配置对象
    public RSAAutoCertificateConfig getCofig() {
        return config;
    }

    public String getAppid() {
        return this.appid;
    }

    public String getMerchantId() {
        return this.merchantId;
    }

    public String getNotifyUrl() {
        return this.notifyUrl;
    }
}
